import { http } from "@/utils/http";
import { baseUrlApi, type BaseRespon } from "./utils";
/** 获取兑换产品列表 */
export type SearchRewardResult = BaseRespon & {
  data: Array<{
    /** 礼品id */
    goodsid: number;
    /** 礼品名称 */
    name: string;
    /** 描述介绍 */
    desc: string;
    /** 兑换积分 */
    point: string;
    /** 图片 */
    photo: string;
    /** 库存 */
    inventory: string;
    /** 是否上架 */
    enable: boolean;
    /** 发货模板 */
    shipping: {
      /** 发货模板编号 */
      shippingid: number;
      /** 发货方式名称 */
      name: string;
      area: null;
    };
  }>;
};
export const getRewardList = (data?: object) => {
  return http.request<SearchRewardResult>("get", baseUrlApi("product/gift"), {
    data
  });
};

/** 获取送货id */
export type ShippingIDResult = {
  /** 用户列表 */
  data: Array<{
    /** 类型编号 */
    shippingid: number;
    /** 名称 */
    name: string;
    area: string;
  }>;
};
export const getShippingID = (data?: object) => {
  return http.request<ShippingIDResult>("get", baseUrlApi("index/shipping"), {
    data
  });
};

/** 获取图片上传token */
export const getUploadToken = (data: string) => {
  return http.request<any>("get", baseUrlApi(`index/storage/sign/${data}`));
};

/** 上传图片方法 */
export const uploadImage = (apiUrl, data) => {
  /** 上传图片请求配置 */
  const axiosConfig = {
    headers: {
      Accept: "*/*",
      "Content-Type": "image/png"
    }
  };
  return http.request<any>("put", apiUrl, { data }, axiosConfig);
};

export const createReward = (data: object) => {
  return http.request<any>("post", baseUrlApi("product/gift"), { data });
};

/** 删除礼品  */
export const deleteReward = (data: Array<number>) => {
  let delConfig = {
    data: data
  };
  return http.request<any>("delete", baseUrlApi("product/gift"), {}, delConfig);
};

/** 修改礼品  */
export const updateReward = (data: object) => {
  let delConfig = {
    data: data
  };
  return http.request<any>("put", baseUrlApi("product/gift"), {}, delConfig);
};

/** 获取兑换订单 */
export const getRewardRecord = () => {
  return http.request<any>("get", baseUrlApi("order/gift"));
};
